<template>
	<view>
		<custom title="账号设置" mode="2" fixed="fixed">
		</custom>

		<!-- icon-jinru -->
		<view class="pl-30 color-333333" style="background-color: #FFFFFF;">
			<view @tap="toPage('/pages/user/edit','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">手机号码</view>
				<view class="mr-16 fs-30 color-999999">{{user_info.phone}}</view>
			</view>
			<!-- <view @tap="toPage('/pages/user/edit','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333 flex-1">修改昵称</view>
				<view class="fs-30">{{user_info.name}}</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view> -->
			<!-- <view @tap="choose_image" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">修改头像</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view> -->
			<!-- <view @tap="toPage('/pages/user/password','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">设置密码</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view> -->
			<!-- 	<view @tap="toPage('/pages/user/pay','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">设置支付密码</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view> -->
			<view @tap="toPage('/pages/protocol/protocol','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">用户协议</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view>
			<view @tap="toPage('/pages/privacy/privacy','',true)" class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">隐私政策</view>
				<view class="iconfont icon-jinru blod fs-40"></view>
			</view>
			<view class="setting-item flex flex-x-b flex-y-center">
				<view class="fs-30 color-333333">版本号</view>
				<view class="fs-30 color-333333 mr-15">{{envinfo.version}}</view>
			</view>
		</view>

		<view class="mt-30 pl-31" style="background-color: #FFFFFF">

			<view @tap="logout" class="abcd flex flex-x-center flex-y-center">
				<!-- <view class="fs-30 color-333333 color-ffffff"></view> -->
				退出登录
			</view>
		</view>

		<toast ref="toast"></toast>
		<!-- <pay></pay> -->
	</view>
</template>

<script>
	let envinfo = require('../../siteinfo.js');
	export default {
		data() {
			return {
				envinfo: envinfo,
			}
		},
		methods: {
			logout() {

				this.$refs.toast.open({
					desc: '确定退出登录？',
					left: '我再想想',
					right: '退出',
					success: () => {
						this.less(() => {
							this.request({
								url: '/login/loginOut',
								method: 'POST',
							}).then(res => {

								// uni.$emit('logout');
								this.vuexSet('user_info', {}, true);
								uni.setStorageSync('ACCESS_TOKEN', '');
								uni.redirectTo({
									url: '/pages/login/login'
								})

								if (getApp().globalData.CHAT && getApp().globalData.CHAT
									.CLOSE) {
									getApp().globalData.CHAT.CLOSE();
								}
							});
						})
					}
				});
				uni.setStorage({
					key: 'openid',
					data: '',
				})



			},
			choose_image() {
				uni.chooseImage({
					sourceType:['album'],
					count: 1,
					success: res => {

						let {
							tempFilePaths = []
						} = res
						console.log('res', res);
						tempFilePaths.forEach(val => {

							// #ifdef APP-PLUS
							uni.compressImage({
								src: val,
								width: '200',
								success: img => {
									this.upload_image(img.tempFilePath);
									console.log('img.tempFilePath', img.tempFilePath);
								},
								fail: err => {
									console.log('err', err);

								}
							});
							// #endif

							// #ifdef H5
							this.upload_image(val);
							// #endif

						})


					}
				})
			},
			upload_image(url) {
				uni.showLoading({
					title: '上传图片中',
					mask: true,
				})
				let appUrl = '/api/common/uploadImages';

				appUrl = envinfo.root + appUrl;


				uni.uploadFile({
					url: appUrl,
					filePath: url,
					data: {
						photo: 'img',
						name: 'img'
					},
					name: 'img',
					header: {
						token: uni.getStorageSync('ACCESS_TOKEN'),
					},
					success: img_data => {
						uni.hideLoading();
						let data = JSON.parse(img_data.data);
						if (img_data.statusCode == 200 && img_data.errMsg == 'uploadFile:ok') {


							if (data.status == 200 && data.data && data.data.imgUrl) {



								this.request({
									url: '/wjuser/user',
									loading: true,
									data: {
										avatarUrl: data.data.imgUrl,
										id: this.user_info.id,
									},
									method: 'PUT',
									loading: true,
								}).then(res => {
									if (res.status == 200) {
										this.showToast('修改成功');

									}
								});






							} else {

							}

						} else {
							this.$refs.toast.open({
								desc: data?.msg || '请稍后重试'
							});
							// this.showToast(data.msg || '请稍后重试');

							if (data.status == 403 || data.status == 4006) {
								// this.toPage('/pages/login/login')
							}
						}

					},
					complete: (res) => {

					},
					fail: res => {
						this.$refs.toast.open({
							desc: data.msg || '请稍后重试'
						});
					}
				})

			},

		}
	}
</script>

<style>
	page {
		background-color: #F0F2F5;

	}

	.setting-item {
		height: 112rpx;
		background-color: #FFFFFF;
		padding-right: 30rpx;
		color: #333 !important;
	}

	.setting-item>view {
		/* color: rgba(255, 255, 255, 1); */
	}

	.setting-item+.setting-item {
		/* border-top: 0.5px solid #D8D8D8; */
		border-top: 0.5px solid #EEEEEE;
	}

	.abcd {


		height: 108rpx;
		background: #FFFFFF;


		color: #333;
	}
</style>
